package com.nkzy.mapper;

import com.nkzy.pojo.User;
import org.apache.ibatis.annotations.*;

import java.math.BigInteger;
import java.util.List;

@Mapper  // IoC控制反转
public interface UserMapper {

    @Insert("INSERT INTO user (username, password, phone, info, status, balance, create_time, update_time) " +
            "VALUES (#{username}, #{password}, #{phone}, #{info}, #{status}, #{balance}, #{createTime}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertUser(User user); // 插入新用户

    @Delete("DELETE FROM user WHERE id = #{id}")
    int deleteUserById(Long id); // 根据ID删除用户

    @Update("UPDATE user SET username = #{username}, password = #{password}, phone = #{phone}, info = #{info}, " +
            "status = #{status}, balance = #{balance}, update_time = #{updateTime} WHERE id = #{id}")
    int updateUser(User user); // 更新用户信息

    @Select("SELECT * FROM user WHERE id = #{id}")
    User selectUserById(Long id); // 根据ID查询用户

    @Select("SELECT * FROM user")
    List<User> selectAllUsers(); // 查询所有用户

    @Select("<script>" +
            "SELECT * FROM user WHERE id IN " +
            "<foreach item='id' index='index' collection='list' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            "</script>")
    List<User> selectUsersByIds(List<Long> ids); // 根据ID列表查询用户
}